package com.jsu.springboot_medicine.service.impl;

import com.jsu.springboot_medicine.dao.MessageDao;
import com.jsu.springboot_medicine.entity.Message;
import com.jsu.springboot_medicine.service.MessageService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @Author wang
 * @Date 2023/9/26 9:04
 */
@Service
public class MessageServiceImpl implements MessageService {
    @Resource
    MessageDao messageDao;

    @Override
    public List<Message> getAllByReceiver(int receiver) {
        return messageDao.getAllByReceiver(receiver);
    }

    @Override
    public List<Message> getAllMessage() {
        return messageDao.getAllMessage();
    }

    @Override
    public List<Message> selectByTitle(String title) {
        return messageDao.selectByTitle(title);
    }

    @Override
    public List<Message> selectByName(String name) {
        return messageDao.selectByName(name);
    }

    @Override
    public List<Message> selectByStatus(Integer status) {
        return messageDao.selectByStatus(status);
    }

    @Override
    public int getReadNum() {
        return messageDao.getReadNum();
    }

    @Override
    public int getUnreadNum(int id) {
        return messageDao.getUnreadNum(id);
    }

    @Override
    public int updateStatus(int id) {
        return messageDao.updateStatus(id);
    }

    @Override
    public void addMessage(Message message) {
        message.setStatus(0);
        message.setCreateTime(new Date());
        message.setUpdateTime(new Date());
        messageDao.addMessage(message);
    }

    @Override
    public void updateMessage(Message message) {
        message.setUpdateTime(new Date());
        messageDao.updateMessage(message);
    }

    @Override
    public int deleteMessage(int id) {
        return messageDao.deleteMessage(id);
    }
}
